//
//  THomeViewController.m
//  LoveShare
//
//  Created by ways on 2017/4/11.
//  Copyright © 2017年 tikeyc. All rights reserved.
//

#import "THomeViewController.h"

#import "JYJTopicViewController.h"
#import "THomeHeadCollectionView.h"

#import "THomeTableView.h"

@interface THomeViewController ()

@property (strong, nonatomic) IBOutlet THomeTableView *homeTableView;
@property (nonatomic,strong)JYJTopicViewController *videoVC;

@property (strong, nonatomic) THomeHeadCollectionView *homeHeadCollectionView;

@end

@implementation THomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    [self setSubViewProperty];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark - init

- (void)setSubViewProperty{
//    [self.view addSubview:self.popMenuPathIconView];
//    [self videoVC];
    
    self.homeTableView.tableHeaderView = self.homeHeadCollectionView;
    
    [self initMJRefresh];
}

- (void)initMJRefresh {
    self.homeTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        //Call this Block When enter the refresh status automatically
        [self loadNewData];
    }];
    // Enter the refresh status immediately
    [self.homeTableView.mj_header beginRefreshing];
    
    self.homeTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        //Call this Block When enter the refresh status automatically
        [self loadMoreData];
    }];
}

- (THomeHeadCollectionView *)homeHeadCollectionView {
    if (!_homeHeadCollectionView) {
        
        _homeHeadCollectionView = [THomeHeadCollectionView initTHomeHeadCollectionView];
        _homeHeadCollectionView.homeVC = self;
    }
    return _homeHeadCollectionView;
}

//- (JYJTopicViewController *)videoVC {
//    if (!_videoVC) {
//        _videoVC = [[JYJTopicViewController alloc] init];
//        _videoVC.isHome = YES;
//        [self.view addSubview:_videoVC.view];
//        
//        [_videoVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(@(0));
//            make.left.equalTo(@(0));
//            make.right.equalTo(@(0));
//            make.bottom.equalTo(self.view.mas_bottom);
//        }];
//        
//        
//        _videoVC.tableView.tableHeaderView = self.homeHeadCollectionView;
//    }
//    return _videoVC;
//}



#pragma mark - 

- (void)loadNewData {
    [self.homeTableView.mj_header performSelector:@selector(endRefreshing) withObject:nil afterDelay:1.0];
}

- (void)loadMoreData {
    [self.homeTableView.mj_footer performSelector:@selector(endRefreshing) withObject:nil afterDelay:1.0];
}



@end
